﻿<%@ Page Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="True" CodeBehind="EditMenu.aspx.cs" Inherits="Cms.Web.UI.Admin.EditMenu" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link rel="Stylesheet" href="Admin/Css/List.css" type="text/css" />
    <link rel="Stylesheet" href="Admin/Css/DragAndDrop.css" type="text/css" />
    <link rel="Stylesheet" href="Admin/Css/EditMenu.css" type="text/css" />
    <script language="javascript" type="text/javascript" src="Admin/edit_area/edit_area_loader.js"></script>
    <script language="javascript" type="text/javascript" src="Admin/Js/Edit.js"></script>
    <script language="javascript" src="Admin/Js/DragAndDrop.js"></script>
    <script language="javascript" type="text/javascript">
        //<![CDATA[
        editAreaLoader.init({
            id: "txtCode",
            syntax: "css",
            start_highlight: true,
            allow_resize: "no",
            allow_toggle: false,
            toolbar: "undo,redo,change_smooth_selection,reset_highlight,highlight,syntax_selection",
            word_wrap: true,
            replace_tab_by_spaces: 4
        });

        function updateCode() {
            txtCode = document.getElementById("txtCode");
            txtCode.value = editAreaLoader.getValue("txtCode");
            document.getElementById("ctl00_body_hidCode").value = txtCode.value;
        }

        function setCodeEditorHeight() {
            var viewportHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
            var codeContainer = document.getElementById("codeContainer");
            var codeHeight = viewportHeight - iLib.Pos.FindY(codeContainer) - 65;
            codeHeight = codeHeight < 100 ? 100 : codeHeight;
            codeContainer.style.height = codeHeight + "px";
        }

        function updatePanels(tab) {
            var pnlProperties = document.getElementById("ctl00_body_pnlProperties");
            var pnlCss = document.getElementById("ctl00_body_pnlCss");
            var pnlItems = document.getElementById("ctl00_body_pnlItems");
            pnlProperties.style.display = "none";
            var width = pnlCss.offsetWidth;
            pnlCss.style.position = "absolute";
            pnlCss.style.left = -10000 + "px";
            pnlCss.style.width = width + "px";
            pnlCss.style.top = "0px";
            pnlItems.style.display = "none";
            switch (tab) {
                case "properties":
                    pnlProperties.style.display = "";
                    break;
                case "css":
                    pnlCss.style.position = "";
                    pnlCss.style.width = "100%";
                    pnlCss.style.left = "0px";
                    break;
                case "items":
                    pnlItems.style.display = "";
                    break;
            }
        }

        var txtName;
        var txtDescription;
	    var txtCode;
	    var originalName;
	    var originalDescription;
	    var originalCode;

	    function init() {
	        setCodeEditorHeight();
	        txtName = document.getElementById("ctl00_body_txtName");
	        txtDescription = document.getElementById("ctl00_body_txtDescription");
	        txtCode = document.getElementById("txtCode");
	        originalName = txtName.value;
	        originalDescription = txtDescription.value;
	        originalCode = document.getElementById("ctl00_body_hidCode").value;
	        editAreaLoader.setValue("txtCode", originalCode);
	    }

	    function isDirty() {
	        var value = originalName == "" ||
	                    originalName != txtName.value ||
	                    originalCode != txtCode.value ||
	                    originalDescription != txtDescription.value;
	        document.getElementById("ctl00_tabs_hidIsDirty").value = value;
	        return value;
	    }

	    function initItemList() {
	        cms.DnD.ClearDropZones();
	        var spans = document.getElementById("itemPane").getElementsByTagName("span");
	        for (var i = 0; i < spans.length; i++) {
	            if (spans[i].parentNode.tagName == "DIV") {
	                cms.DnD.AddDropZone(spans[i]);
	                spans[i].parentNode.id = "T" + spans[i].id.substring(1);
	                cms.DnD.AddDropZone(spans[i].parentNode);
	                iLib.Dom.AddListener(spans[i], "mouseover", function(e) {
	                    if (cms.DnD.GetIsDragging())
	                        return;
	                    e = e || window.event;
	                    var target = e.target || e.srcElement;
	                    while (target.parentNode && target.parentNode.tagName != "DIV")
	                        target = target.parentNode;
	                    target.className = "hover";
	                });
	                iLib.Dom.AddListener(spans[i], "mouseout", function(e) {
	                    if (cms.DnD.GetIsDragging())
	                        return;
	                    e = e || window.event;
	                    var target = e.target || e.srcElement;
	                    while (target.parentNode && target.parentNode.tagName != "DIV")
	                        target = target.parentNode;
	                    target.className = "";
	                });
	                iLib.Dom.AddListener(spans[i], "mousedown", function(e) {
	                    cms.DnD.InitDrag("DIV", e);
	                });
	                iLib.Dom.AddListener(spans[i], "click", function(e) {
	                    e = e || window.event;
	                    var target = e.target || e.srcElement;
	                    var ddlVersions = document.getElementById("ctl00_body_ddlVersions");
	                    var ddlLocales = document.getElementById("ctl00_body_ddlLocales");
	                    var baseUrl = window.location.protocol + "//" + window.location.host + "/Admin/";
	                    window.location.href = baseUrl + "EditMenuItem.aspx?id=" + target.parentNode.id.substring(1) +
	                                "&menuid=" + document.getElementById("ctl00_tabs_hidMenuID").value +
	                                "&versionid=" + ddlVersions[ddlVersions.selectedIndex].value +
	                                "&localeid=" + ddlLocales[ddlLocales.selectedIndex].value;
	                });
	            }
	        }
	        var imgs = document.getElementById("itemPane").getElementsByTagName("img");
	        for (var i = 0; i < imgs.length; i++) {
	            if (imgs[i].parentNode.tagName == "SPAN") {
	                iLib.Dom.AddListener(imgs[i], "click", function(e) {
	                    e = e || window.event;
	                    var target = e.target || e.srcElement;
	                    iLib.Dom.PreventBubble(e);
	                    prepareItemPopup(target, target.parentNode.id, e);
	                });
	            }
	        }
	        cms.DnD.AddStartDragHandler(onStartDrag);
	        cms.DnD.AddEndDragHandler(onEndDrag);
	    }

	    function onEndDrag(draggedElement, dropzoneElement, dropzonePart) {
	        document.getElementById("ctl00_body_hidDraggedID").value = draggedElement.id;
	        document.getElementById("ctl00_body_hidDropzoneID").value = dropzoneElement != null ? dropzoneElement.id : "";
	        document.getElementById("ctl00_body_hidDropzonePart").value = dropzonePart;
	        if (dropzoneElement != null && draggedElement.id != dropzoneElement.id) {
	            cms.Lists.ShowPaneOverlay("itemPaneOverlay");
	            __doPostBack('ctl00$body$lbDragEnd', '');
	        }
	    }

	    function onStartDrag(e) {
	        cms.Lists.HidePopups(e);
	    }
	    
	    function prepareItemPopup(trigger, id, e) {
	        //alert(id);
	        var popup = document.getElementById("pnlItemPopup");
	        var hlEditMenuItem = document.getElementById("hlEditMenuItem");
	        var ddlVersions = document.getElementById("ctl00_body_ddlVersions");
	        var ddlLocales = document.getElementById("ctl00_body_ddlLocales");
	        hlEditMenuItem.href = "Admin/EditMenuItem.aspx?id=" + id.substring(1) +
	                                "&menuid=" + document.getElementById("ctl00_tabs_hidMenuID").value +
	                                "&versionid=" + ddlVersions[ddlVersions.selectedIndex].value +
	                                "&localeid=" + ddlLocales[ddlLocales.selectedIndex].value;
	        document.getElementById("ctl00_body_hidDeleteMenuItemID").value = id;
	        cms.Lists.ShowPopup(popup, trigger, "left", 0, 0, true, e);
	    }

	    //]]>
	</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="buttons" runat="server">
    <asp:UpdatePanel ID="upnlButtons" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
        <ContentTemplate>
            <asp:HyperLink ID="hlNewMenuItem" runat="server" CssClass="orangeButton"><span id="lblNewMenu1" runat="server"><span id="lblNewMenu2" runat="server"><img id="imgNewMenu" runat="server" src="Admin/Img/icons/chart_organisation_add.png" alt="" /><span id="lblNewMenu3" runat="server"><cms:LocalizedLiteral ID="llNewMenuItem" runat="server" /></span></span></span></asp:HyperLink>
            <asp:LinkButton ID="lbSave" runat="server" OnClick="lbSave_Click" OnClientClick="isDirty(); updateCode();" CssClass="orangeButton"><span id="lblSave1" runat="server"><span id="lblSave2" runat="server"><img id="imgSave" runat="server" src="Admin/Img/icons/disk.png" alt="" /><span id="lblSave3" runat="server"><cms:LocalizedLiteral ID="llSave" runat="server" /></span></span></span></asp:LinkButton>
            <asp:HyperLink ID="hlCancel" runat="server" NavigateUrl="Admin/Menus.aspx" class="orangeButton"><span id="lblCancel1" runat="server"><span id="lblCancel2" runat="server"><img id="imgCancel" runat="server" src="Admin/Img/icons/delete.png" alt="" /><span id="lblCancel3" runat="server"><cms:LocalizedLiteral ID="llCancel" runat="server" /></span></span></span></asp:HyperLink>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="tabs" runat="server">
    <asp:UpdatePanel ID="upnlTabs" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
        <ContentTemplate>
            <cms:AdminTabStrip ID="tabStrip" runat="server" SelectedValue="properties" OnChange="tabStrip_Click">
                <cms:AdminTabItem ID="tiProperties" runat="server" value="properties" EnabledImage="Admin/Img/icons/menu_edit.png"><cms:LocalizedLiteral ID="llPropertiesTab" runat="server" /></cms:AdminTabItem>
                <cms:AdminTabItem ID="tiCss" runat="server" value="css" EnabledImage="Admin/Img/icons/css.png"><cms:LocalizedLiteral ID="llCssTab" runat="server" /></cms:AdminTabItem>
                <cms:AdminTabItem ID="tiItems" runat="server" value="items" EnabledImage="Admin/Img/icons/chart_organisation.png"><cms:LocalizedLiteral ID="llItemsTab" runat="server" /></cms:AdminTabItem>
            </cms:AdminTabStrip>
            <input type="hidden" id="hidIsDirty" runat="server" />
            <input type="hidden" id="hidSave" runat="server" />
            <input type="hidden" id="hidMenuID" runat="server" />
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="body" runat="server">
    <asp:Literal ID="litIcon" runat="server" Visible="false" Text="Admin/Img/Icons/menu_edit.png" />
    
    <asp:Panel ID="pnlCss" runat="server" CssClass="pnlTab">
        <asp:UpdatePanel ID="upnlCss" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <input type="hidden" id="hidCode" runat="server" />
                <input type="hidden" id="hidSaveCode" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <div id="codeContainer" style="height: 400px;">
            <textarea id="txtCode" cols="10" rows="10" style="width: 100%; height: 100%;"></textarea>
        </div>
        <div class="pnlTabOverlay"></div>
    </asp:Panel>
    
    <asp:Panel ID="pnlProperties" runat="server" CssClass="pnlTab">
        <asp:UpdatePanel ID="upnlProperties" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <table class="editForm">
                    <tr>
                        <td><cms:LocalizedLiteral ID="llName" runat="server" />:</td>
                        <td><asp:TextBox ID="txtName" runat="server" MaxLength="255" Width="600" /></td>
                    </tr>
                    <tr valign="top">
                        <td style="padding-top: 4px;"><cms:LocalizedLiteral ID="llDescription" runat="server" />:</td>
                        <td><asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" Width="600" Rows="10" /></td>
                    </tr>
                </table>
                <div class="horizontalDivider" style="margin-top: 8px; margin-bottom: 10px;"></div>
                <table class="editForm">
                    <tr>
                        <td><cms:LocalizedLiteral ID="llItemIsActiveWhenSubItemIsActive" runat="server" />:</td>
                        <td><asp:CheckBox ID="chkItemIsActiveWhenSubItemIsActive" runat="server" /></td>
                    </tr>
                    <tr>
                        <td><cms:LocalizedLiteral ID="llSubMenuBehaviour" runat="server" />:</td>
                        <td>
                            <table border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td style="padding-right: 0px;"><asp:RadioButton ID="rbToggle" runat="server" GroupName="Behaviours" /></td>
                                    <td><cms:LocalizedLiteral ID="llToggle" runat="server" /></td>
                                </tr>
                                <tr>
                                    <td style="padding-right: 0px;"><asp:RadioButton ID="rbOpenExclusively" runat="server" GroupName="Behaviours" /></td>
                                    <td><cms:LocalizedLiteral ID="llOpenExclusively" runat="server" /></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td><cms:LocalizedLiteral ID="llNumberOfExtraWrapperSpans" runat="server" />:</td>
                        <td><asp:DropDownList ID="ddlNumberOfExtraWrapperSpans" runat="server">
                            <asp:ListItem Value="0">0</asp:ListItem>
                            <asp:ListItem Value="1">1</asp:ListItem>
                            <asp:ListItem Value="2">2</asp:ListItem>
                            <asp:ListItem Value="3">3</asp:ListItem>
                            <asp:ListItem Value="4">4</asp:ListItem>
                            <asp:ListItem Value="5">5</asp:ListItem>
                        </asp:DropDownList></td>
                    </tr>
                    <tr>
                        <td><cms:LocalizedLiteral ID="llActiveItemPrefix" runat="server" />:</td>
                        <td><asp:TextBox ID="txtActiveItemPrefix" runat="server" MaxLength="255" /></td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
        <div class="pnlTabOverlay"></div>
    </asp:Panel>

    <asp:Panel ID="pnlItems" runat="server" CssClass="pnlTab">
        <asp:UpdatePanel ID="upnlItems" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <table class="editForm">
                    <tr>
                        <td><cms:LocalizedLiteral ID="llLocale" runat="server" />:</td>
                        <td><asp:DropDownList ID="ddlLocales" runat="server" OnSelectedIndexChanged="ddlLocales_IndexChanged" AutoPostBack="true" /></td>
                        <td><cms:LocalizedLiteral ID="llVersion" runat="server" />:</td>
                        <td><asp:DropDownList ID="ddlVersions" runat="server" OnSelectedIndexChanged="ddlVersions_IndexChanged" AutoPostBack="true" /></td>
                        <td><asp:LinkButton ID="lbPublish" runat="server" OnClick="lbPublish_Click" CssClass="orangeButton"><span id="s1" runat="server"><span id="s2" runat="server"><img src="Admin/Img/icons/page_white_go.png" alt="" id="imgPublish" runat="server" /><span id="s3" runat="server"><cms:LocalizedLiteral ID="llPublish" runat="server" /></span></span></span></asp:LinkButton></td>
                        <td><cms:LocalizedLiteral ID="llPublishedVersion" runat="server" />: <asp:LinkButton ID="lbSelectPublishedVersion" runat="server" OnClick="lbSelectPublishedVersion_Click" /><cms:LocalizedLiteral ID="llNoVersionPublished" runat="server" /></td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
        <div class="horizontalDivider" style="margin-top: 5px; margin-bottom: 8px;"></div>
        <div id="itemPane">
            <asp:UpdatePanel ID="upnlItemsList" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
                <ContentTemplate>
                    <asp:Panel ID="pnlItemActions" runat="server" />
                    <table class="list" cellspacing="0" border="0">
                        <tr>
                            <th><cms:LocalizedLiteral ID="llItemNameHeader" runat="server" /></th>
                            <th><cms:LocalizedLiteral ID="llLinksToHeader" runat="server" /></th>
                            <th><cms:LocalizedLiteral ID="llTargetHeader" runat="server" /></th>
                            <th>&nbsp;</th>
                            <th><cms:LocalizedLiteral ID="llActiveForCategoryHeader" runat="server" /></th>
                        </tr>
                        <asp:Repeater ID="rpItems" runat="server" OnItemDataBound="rpItems_ItemDataBound">
                            <ItemTemplate>
                                <tr>
                                    <td style="padding: 0px;"><asp:Literal ID="litID" runat="server" /><img id="imgItem" runat="server" /><span><asp:literal ID="litName" runat="server" /></span><asp:Literal ID="litCloser" runat="server" /></td>
                                    <td><asp:Literal ID="litLinksTo" runat="server" /></td>
                                    <td><asp:Literal ID="litTarget" runat="server" /></td>
                                    <td><asp:Literal ID="litSortIndex" runat="server" Visible="false" /></td>
                                    <td><asp:Literal ID="litActiveForCategory" runat="server" /></td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                        <tr id="trNoHits" runat="server">
                            <td colspan="2"><cms:LocalizedLiteral ID="llNoHits" runat="server" /></td>
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:UpdatePanel>
            <div id="itemPaneOverlay" class="paneOverlay"></div>
            <div id="itemPaneOverlayProgress" class="paneOverlayProgress"><img src="Admin/img/progress.gif" /></div>
        </div>
        <div class="pnlTabOverlay"></div>
    </asp:Panel>

    <asp:UpdatePanel ID="upnlActions" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
        <ContentTemplate>
            <div id="pnlItemPopup" class="popup">
                <div class="popupMenuTop">
                    <div class="popupMenuTopBg">&nbsp;</div>
                    <div class="popupMenuTopLeftCorner">&nbsp;</div>
                    <div class="popupMenuTopRightCorner">&nbsp;</div>
                </div>
                <div class="popupMenu">
                    <div class="popupMenuLeftBg">&nbsp;</div>
                    <div class="popupMenuRightBg">&nbsp;</div>
                    <div class="popupMenuContent">
                        <a id="hlEditMenuItem" href="Admin/EditMenuItem.aspx"><img src="Admin/Img/icons/folder_edit.png" /><span><cms:LocalizedLiteral ID="llEditMenuItem" runat="server" /></span></a>
                        <div class="horizontalDivider" style="margin-bottom: 3px; margin-top: 4px; margin-left: 27px; margin-right: 4px;"></div>
                        <asp:LinkButton ID="lbDeleteMenuItem" runat="server" OnClick="lbDeleteMenuItem_Click"><img id="imgDeleteMenuItem" runat="server" src="Admin/Img/icons/cross.png" /><span id="lblDeleteMenuItem" runat="server"><cms:LocalizedLiteral ID="llDeleteMenuItem" runat="server" /></span></asp:LinkButton>
                    </div>
                </div>
                <div class="popupMenuBottom">
                    <div class="popupMenuBottomBg">&nbsp;</div>
                    <div class="popupMenuBottomLeftCorner">&nbsp;</div>
                    <div class="popupMenuBottomRightCorner">&nbsp;</div>
                </div>
            </div>
            <input type="hidden" id="hidDeleteMenuItemID" runat="server" />
            <input type="hidden" id="hidDraggedID" runat="server" />
            <input type="hidden" id="hidDropzoneID" runat="server" />
            <input type="hidden" id="hidDropzonePart" runat="server" />
            <asp:LinkButton ID="lbDragEnd" runat="server" OnClick="lbDragEnd_Click" Text="DragEnd" style="position: absolute; left: -10000px;" />
        </ContentTemplate>
    </asp:UpdatePanel>

    <script language="javascript">
        //<![CDATA[
        iLib.Dom.AddListener(window, "load", init);
        iLib.Dom.AddListener(window, "load", initItemList);
        cms.Ajax.Init();
        cms.Ajax.AddEndRequestHandler(cms.Edit.HideTabOverlays);
        cms.Ajax.AddEndRequestHandler(cms.Lists.HidePaneOverlays);
        //]]>
    </script>
    
</asp:Content>
